import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';

import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';
import { HintsService } from '../../../public/serve/hints/hints.service';
import { InitService } from '../../../public/serve/init/init.service';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
import { Service } from '../../../server/server';
import { internal } from '../../internal.data';
import { ActivatedRoute, Params, Router } from '@angular/router';
declare var $: any;
@Component({
  selector: 'app-indexing-audit',
  templateUrl: './indexing-audit.component.html',
  styleUrls: ['./indexing-audit.component.css']
})
export class IndexingAuditComponent implements OnInit {

  @Input() internalParam : any;
  @Output() onSubmit = new EventEmitter<void>();
	id:any;
	checkStatus:any = '200';

	constructor(public initService: InitService,
		private server: Service,
		private request: CudTableService,
    private hintsService: HintsService,
		private activatedRoute: ActivatedRoute,
		public router: Router
    ) { }

	ngOnInit() {
    this.activatedRoute.queryParams.subscribe((p: Params) => {
      this.id = p['id'];
  });
	}

	_checkStatus(status:any){
		this.checkStatus = status;
	}

	/**
	 * 产品内容审核
	 */
	_onSubmit(info: any) {
		info.token = internal.retrieval.token;
		info.id = this.id;
		info.productId = this.internalParam.productId;
		info.taskId = this.internalParam.taskId;
		info.updateBy = this.server.getuserName();
		info.checkStatus = this.checkStatus;
		this.request.postRequest(this.server.baseUrl + "Service/Task/updateTaskProductCheckStatus", info).then(res => {
			if (res.result_code == '0000') {
				this.onSubmit.emit();
				setTimeout(()=>{
					this.server.closeCurrentPageEimt.emit(this.router.url);
				},1000);
			}
			this.hintsService.messages(res.message, res.result_code);
			$("#indexingAuditModel").modal("hide");
			return;
		}).catch((err: any) => {
			this.hintsService.messages('error', 'error');
			$("#indexingAuditModel").modal("hide");
			return;
		});
	}

}
